package com.shanshan.system.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * @author keluoyisi
 * @program: starter01
 * @description:
 * @date 2022-11-18 15:50:12
 */
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket docket(){
        //创建表
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        //组名
        docket.groupName("保时捷");
        //api信息
        docket.apiInfo(getInfo());
        //选择哪些生成api接口---根据请求路径选择和根据包名选择
        docket.select().apis(RequestHandlerSelectors.basePackage("com.shanshan.system.controller"));
//        docket.select().paths(Predicates.and(PathSelectors.regex("/*/.*")))
//                .build();
        return docket;
    }

    public ApiInfo getInfo(){
        Contact contact = new Contact("刘彤彤", "http://www.baidu.com", "0707@qq.com");
        ApiInfo info = new ApiInfo("汽车出租系统","增删改查API","1.1.1",
                "http://www.baidu.com",contact,"保时捷",
                "http://www.baidu.com",new ArrayList<VendorExtension>());
        return info;
    }
}


//@Configuration
//public class SwaggerConfig {
//
//    @Bean
//    public Docket createRestApi() {
//        String version = "3.X版本";
//        Docket docket = new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(new ApiInfoBuilder()
//                        .title("汽车租贷系统")
//                        .description("/---这是汽车租贷系统接口文档---/")
//                        .termsOfServiceUrl("http://www.baidu.com")
//                        .contact(new Contact("太阳偷渡青山", "http://www.baidu.com", "2387371611@qq.com"))
//                        .version(version)
//                        .build())
//                //分组名称
//                .groupName("第七组")
//                .select()
//                //这里指定Controller扫描包路径
//                .apis(RequestHandlerSelectors.basePackage("com.cwh.controller"))
//                .paths(PathSelectors.any())
//                .build();
//        return docket;
//    }
//}